package com.punai.config.controller;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.config.service.ConfigTemplateService;
import com.punai.config.sqlitedomain.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/config/indicatorTemplate")
public class ConfigTemplateController extends BaseController {

    @Autowired
    private ConfigTemplateService configTemplateService;

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        TableDataInfo resList = configTemplateService.selectTemplateList();
        return resList;
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:list')")
    @GetMapping("/listNoPage")
    public AjaxResult listNoPage() {
        return AjaxResult.success(configTemplateService.selectAllTemplate());
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        return AjaxResult.success(configTemplateService.findOne(id));
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:query')")
    @GetMapping("/getNewCode")
    public AjaxResult getNewCode() {
        return AjaxResult.success("成功",configTemplateService.getNewCode());
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:add')")
    @PostMapping
    public AjaxResult addTemplate(@RequestBody Template template) {
        configTemplateService.saveTemplate(template);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:edit')")
    @PutMapping
    public AjaxResult updateTemplate(@RequestBody Template template) {
        configTemplateService.saveTemplate(template);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplate:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult indicatorTemplate(@PathVariable String id) {
        configTemplateService.removeTemplate(id);
        return AjaxResult.success();
    }

}
